package com.Maykk.Demo13;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @ClassName: Demo01
 * @Description: TODO 翻页效果
 * @Author: MaykkStar@163.com
 */
public class Demo01 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        initList(list);
        // 设置每页的内容个数
        final int PAGE_COUNT = 5;
        // 设置最大页数
        final int MAX_PAGE = list.size() / PAGE_COUNT + (list.size() % PAGE_COUNT != 0 ? 1 : 0);
        int page = 0;
        for (;;) {
            list.stream().skip(page * PAGE_COUNT).limit(PAGE_COUNT).forEach(System.out::println);
            System.out.println("N -- 下一页，B -- 上一页");
            switch (new Scanner(System.in).next()) {
                case "N":
                case "n":
                    page = Math.min(page + 1, MAX_PAGE - 1);
                    System.out.println("第" + (page + 1) + "页");
                    break;
                case "B":
                case "b":
                    page = Math.max(page - 1, 0);
                    System.out.println("第" + (page + 1) + "页");
                    break;
                default:
                    System.out.println("输入错误！~");
            }
        }
    }

    private static void initList(ArrayList<String> list) {
        list.add("郭德纲");
        list.add("郭麒麟");
        list.add("郭汾阳");
        list.add("郭美美");
        list.add("郭阳");
        list.add("郭亮");
        list.add("郭靖");
        list.add("黄蓉");
        list.add("小龙女");
        list.add("迪丽热巴");
        list.add("古力娜扎");
    }
}
